package modelo.bd.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import modelo.bd.Conexion;
import modelo.bd.exception.DAOException;

abstract class AbstractDAO<T> {

    private String query;
    public Conexion con;

    protected String getQuery() {
        return query;
    }

    protected void setQuery(String query) {
        this.query = query;
    }

    public AbstractDAO() {
        this.con = Conexion.instancia();
        try {
            con.crear();
        } catch (ClassNotFoundException ex) {
            //Logger.getLogger(AbstractDAO.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            //Logger.getLogger(AbstractDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public abstract void add(T entity) throws DAOException;

    public abstract void deleteWhere(String condition) throws DAOException;

    public abstract void update(T entity) throws DAOException;

    protected abstract ArrayList<T> select() throws DAOException;

    public abstract ArrayList<T> selectAll() throws DAOException;

    public abstract ArrayList<T> selectWhere(String condition) throws DAOException;
}
